import {BaseBehavior, CanvasEvent, register, ExtensionCategory, Graph} from '@antv/g6';
import {generateId} from '@/utils/methods'

function clickAddNode() {
    class ClickAddNode extends BaseBehavior {
        constructor(context, options) {
            super(context, options);
            const {graph} = this.context;
            graph.on(CanvasEvent.DBLCLICK, (event) => {
                const {x, y} = event.canvas;
                graph.addNodeData([
                    {
                        id: 'node-' + generateId(),
                        style: {
                            x,
                            y,
                            labelText: "未命名"
                        },
                    },
                ]);
                graph.draw();
            });
        }
    }

    register(ExtensionCategory.BEHAVIOR, 'createNode', ClickAddNode);
    return 'createNode'
}

export default clickAddNode
